package org.jeecg.modules.fund.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.fund.entity.UserhomeOrder;
import org.jeecg.modules.fund.service.IUserhomeOrderService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 基金订单表
 * @Author: jeecg-boot
 * @Date:   2024-08-29
 * @Version: V1.0
 */
@Api(tags="基金订单表")
@RestController
@RequestMapping("/fund/userhomeOrder")
@Slf4j
public class UserhomeOrderController extends JeecgController<UserhomeOrder, IUserhomeOrderService> {
	@Autowired
	private IUserhomeOrderService userhomeOrderService;
	
	/**
	 * 分页列表查询
	 *
	 * @param userhomeOrder
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "基金订单表-分页列表查询")
	@ApiOperation(value="基金订单表-分页列表查询", notes="基金订单表-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<UserhomeOrder>> queryPageList(UserhomeOrder userhomeOrder,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		UserhomeOrder temp=new UserhomeOrder();
		if(oConvertUtils.isNotEmpty(userhomeOrder.getStatus()))
		{
			temp.setStatus(userhomeOrder.getStatus());
			userhomeOrder.setStatus(null);
		}
		if(oConvertUtils.isNotEmpty(userhomeOrder.getType()))
		{
			temp.setType(userhomeOrder.getType());
			userhomeOrder.setType(null);
		}
		QueryWrapper<UserhomeOrder> queryWrapper = QueryGenerator.initQueryWrapper(userhomeOrder, req.getParameterMap());
		Page<UserhomeOrder> page = new Page<UserhomeOrder>(pageNo, pageSize);
		if(oConvertUtils.isNotEmpty(userhomeOrder.getFundname()))
		{
			queryWrapper.like("g.name",userhomeOrder.getFundname());
		}
		if(oConvertUtils.isNotEmpty(userhomeOrder.getFcode()))
		{
			queryWrapper.eq("g.fcode",userhomeOrder.getFcode());
		}
		if(oConvertUtils.isNotEmpty(userhomeOrder.getPhone()))
		{
			queryWrapper.like("u.phone",userhomeOrder.getPhone());
		}
		if(oConvertUtils.isNotEmpty(userhomeOrder.getUsername()))
		{
			queryWrapper.like("u.username",userhomeOrder.getUsername());
		}
		if(oConvertUtils.isNotEmpty(temp.getStatus()))
		{
			queryWrapper.eq("a.status",temp.getStatus());
		}
		if(oConvertUtils.isNotEmpty(temp.getType()))
		{
			queryWrapper.eq("a.type",temp.getType());
		}
		if(oConvertUtils.isNotEmpty(temp.getBankName()))
		{
			queryWrapper.like("h.bank_name",temp.getType());
		}
		if(oConvertUtils.isNotEmpty(temp.getBankNumber()))
		{
			queryWrapper.like("h.bank_number",temp.getBankNumber());
		}
		IPage<UserhomeOrder> pageList = userhomeOrderService.pageList(page, queryWrapper);
		return Result.OK(pageList);
	}
	



	 /**
	  *  补单
	  *
	  * @param userhomeOrder
	  * @return
	  */
	 @AutoLog(value = "基金订单表-补单")
	 @ApiOperation(value="基金订单表-补单", notes="基金订单表-补单")
	 //@RequiresPermissions("org.jeecg.modules:userhome_order:edit")
	 @RequestMapping(value = "/supplement", method = {RequestMethod.PUT,RequestMethod.POST})
	 public Result<?> supplement(@RequestBody UserhomeOrder userhomeOrder) {
		 return userhomeOrderService.handleSupplement(userhomeOrder.getOrderNum());
	 }

	

	

	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "基金订单表-通过id查询")
	@ApiOperation(value="基金订单表-通过id查询", notes="基金订单表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<UserhomeOrder> queryById(@RequestParam(name="id",required=true) String id) {
		UserhomeOrder userhomeOrder = userhomeOrderService.getById(id);
		if(userhomeOrder==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(userhomeOrder);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param userhomeOrder
    */
    //@RequiresPermissions("org.jeecg.modules:userhome_order:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, UserhomeOrder userhomeOrder) {
        return super.exportXls(request, userhomeOrder, UserhomeOrder.class, "基金订单表");
    }



	 /**
	  *  补单
	  *
	  * @param userhomeOrder
	  * @return
	  */
	 @AutoLog(value = "用户钱包提现-提现")
	 @ApiOperation(value="用户钱包提现-提现", notes="用户钱包提现-提现")
	 //@RequiresPermissions("org.jeecg.modules:userhome_order:edit")
	 @RequestMapping(value = "/examine", method = {RequestMethod.POST})
	 public Result<?> examine(@RequestBody UserhomeOrder userhomeOrder) {
		 return userhomeOrderService.examine( userhomeOrder);
	 }



	 /**
	  *  补单
	  *
	  * @param userhomeOrder
	  * @return
	  */
	 @AutoLog(value = "赎回-审核")
	 @ApiOperation(value="赎回-审核", notes="赎回-审核")
	 //@RequiresPermissions("org.jeecg.modules:userhome_order:edit")
	 @RequestMapping(value = "/examineFund", method = {RequestMethod.POST})
	 public Result<?> examineFund(@RequestBody UserhomeOrder userhomeOrder) {
		 return userhomeOrderService.examineFund( userhomeOrder);
	 }



	 /**
	  *  补单
	  *
	  * @param userhomeOrder
	  * @return
	  */
	 @AutoLog(value = "基金钱包提现-审核")
	 @ApiOperation(value="基金钱包提现-审核", notes="基金钱包提现-审核")
	 //@RequiresPermissions("org.jeecg.modules:userhome_order:edit")
	 @RequestMapping(value = "/examineFundMoney", method = {RequestMethod.POST})
	 public Result<?> examineFundMoney(@RequestBody UserhomeOrder userhomeOrder) {
		 return userhomeOrderService.examineFundMoney( userhomeOrder);
	 }






 }
